package com.example.perplonews.a_c_network

class HttpFactory private constructor(){
    companion object{
        val instance:HttpFactory by lazy (mode = LazyThreadSafetyMode.SYNCHRONIZED){
            HttpFactory()
        }
    }

    private var upload: HttpImpl? = null
    private  var sign:HttpImpl? = null
    private  var tokenSign:HttpImpl? = null
    private  var token:HttpImpl? = null

    fun factory(type: HttpType): HttpImpl {
        var http: HttpImpl? = null
        when (type) {
            HttpType.UPLOADTYPE -> {
                if (upload == null) upload = TokenSignRetrofit.Build().build()
                http = upload
            }
            HttpType.SIGNTYPE -> {
                if (sign == null) sign = TokenSignRetrofit.Build().build()
                http = sign
            }
            HttpType.TOKENSIGNTYPE -> {
                if (tokenSign == null) tokenSign = TokenSignRetrofit.Build().build()
                http = tokenSign
            }
            HttpType.TOKEN -> {
                if (token == null) token = TokenRetrofit.Build().build()
                http = token
            }
        }
        return http!!
    }


}